package nju.mscs.businesslogic;
import java.io.FileNotFoundException;
import java.io.IOException;

import nju.mscs.data.DataServerManager;
import nju.mscs.data.object.*;

public class LogIn {
	public static String dbFile="Database.ser";
	static protected User user;
	static protected Database db;//现有一个数据库
	static String num="0";
	public LogIn(){
		if(db==null){
			try {
				db=new DataServerManager().readData(dbFile);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public int matching(String id,String password,int type){	
	    if((user=db.searchUserById(id))!=null&&user.getPassword().equals(password)&&user.getType()==type){
	    	new BackStage();
	    		if(user.getType()==user.SHOP_MANAGER&&BackStage.hasGift){
	    			return 2;
	    		}
	    		else
	    			return 1;
	    	}
	    else
	    	return 0;
	}
}

